home *** CD-ROM | disk | FTP | other *** search
- /***
- * Created by Bill Hubauer on Fri, Jun 21, 1996 @ 2:53 AM.
- *
- ***/
-
-
- #ifndef __GunSprite_H__
- #include "GunSprite.h"
- #endif
-
-
-
-
-
- void CGunSprite::UpdatePosition() //Override
- {
- if(SpaceDownQ()){
- FireGun();
- }else{
-
- short newPos = GetLocation()->left;
- const Rect& bounds = *GetGameBounds();
-
- if(LeftArrowQ()){
- newPos -= kMoveInterval;
- }else if(RightArrowQ()){
- newPos += kMoveInterval;
- }
-
- if(newPos < bounds.left){
- newPos = bounds.left;
- }else if(newPos > (bounds.right - Width())){
- newPos = bounds.right - Width();
- }
-
- MoveBy(newPos - GetLocation()->left,0);
- }
- }
-
-
- static short CalcGunTop(CSpriteWorld* world)
- {
- const Rect& bounds = *(world->GetSpriteCanvas()->GetBounds());
-
- return bounds.bottom - 32;
- }
-
- inline short RectWidth(const Rect& r)
- {
- return r.right - r.left;
- }
-
- static short CalcGunLeft(CSpriteWorld* world)
- {
- const Rect& bounds = *(world->GetSpriteCanvas()->GetBounds());
-
- return ((bounds.left + (RectWidth(bounds) / 2)) - 16);
- }
-
- CGunSprite::CGunSprite(CSpriteWorld* world,CSpriteGame* game)
- : CGameSprite(world, game, 0,game->GetImage(kBaseImageID), CalcGunTop(world),
- CalcGunLeft(world), game->GetImageMask(kBaseImageID))
- {
-
- }
-
-
- CGunSprite::~CGunSprite()//Override
-
- {
-
- }
-
-
-
-
-
-
-
- Boolean CGunSprite::LeftArrowQ()
- {
- return KeyIsDownQ(0x7B);
- }
-
-
- Boolean CGunSprite::RightArrowQ()
- {
- return KeyIsDownQ(0x7C);
- }
-
- Boolean CGunSprite::SpaceDownQ()
- {
- return KeyIsDownQ(0x31);
- }
-
-
- void CGunSprite::FireGun()
- {
- short deltaV,deltaH;
-
- deltaV = -75;
- deltaH = 0;
-
-
- new CBulletSprite(GetWorld(), GetGame(), GetLocation()->top, GetLocation()->left,
- deltaV, deltaH);
-
- PlaySound(kGunSoundID);
-
- }
-
-
-
-
- CBulletSprite::CBulletSprite(CSpriteWorld* world,CSpriteGame* game,short startTop,short startLeft,
- short deltaV,short deltaH)
- : CGameSprite(world, game, 0, game->GetImage(kBulletImageID), startTop, startLeft,
- game->GetImageMask(kBulletImageID)),
- fDeltaV(deltaV),
- fDeltaH(deltaH)
- {
-
- }
-
-
- CBulletSprite::~CBulletSprite()//Override
-
- {
-
- }
-
-
- void CBulletSprite::UpdatePosition()//Override
- {
- MoveBy(fDeltaH,fDeltaV);
- if(OutOfBoundsQ()){
- delete this;
- }
- }
-
- void CBulletSprite::WasHitBy(CSprite* s)//Override
- {
-
- }
-
-